package org.hk.kg.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.MalformedURLException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

import org.hk.kg.utils.LocalResouce;

public class LoaderFrame{
	private JWindow splashWin;
	
	public void prepareSplash(JFrame containner)
	{
		splashWin = new JWindow(containner);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		
		Image image;
		try {
			image = toolkit.getImage(LocalResouce.getImage("syspic/loader_pic.jpg"));
		} catch (MalformedURLException e) {
			return;
		}
		JLabel label = new JLabel();
		label.setSize(new Dimension(100,100));
		label.setIcon(new ImageIcon(image));
		label.setBackground(Color.red);
		label.setVisible(true);
		splashWin.add(label);
		int imgWidth = image.getWidth(containner);
		int imgHeight = image.getHeight(containner);
		splashWin.setSize(imgWidth, imgHeight);
		splashWin.setLocationRelativeTo(containner);
		splashWin.setVisible(true);
	}
	
	public void startSplash(){
		splashWin.setVisible(true); 
		splashWin.toFront();
	}
	public void stopSplash(){ 
		splashWin.dispose();
	}
}
